﻿//-----------------------------------------------------------------------
// <copyright>
//     Copyright (c) Artur Mustafin. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Diagnostics;
using System.Windows.Forms;
using Math.Compiler;
using Math.Compiler.Classes;

namespace Math.Application
{
    public partial class Main : Form
    {
        private Core _core = new Core();

        public Main()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                _core.LoadFromStrings(textBox1.Lines);
                sw.Stop();
                toolStripStatusLabel1.Text = string.Format("{0} ms", sw.ElapsedMilliseconds);
            }
            catch (MathException ex)
            {
                toolStripStatusLabel1.Text = ex.Message;
                return;
            }
            finally
            {
                listView1.BeginUpdate();
                listView1.Items.Clear();
                foreach (Variable variable in _core.Variablies)
                {
                    ListViewItem item = new ListViewItem(new string[] 
                    {
                        variable.Name,
                        variable.Text,
                        variable.Value
                    });
                    listView1.Items.Add(item);
                }
                listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
                listView1.EndUpdate();
            }
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
